package com.wangtao.firstapp.utils;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;

/**
 * 自定义Toast “成功收入至 [ 我的喜欢 ]”
 * Created by lanouhn on 16/9/13.
 */
public class ToastUtils {

    private Context context;

    public ToastUtils(Context context) {
        this.context = context;
    }

    public void toast(String stringT, int time) {
        final Toast toast = new Toast(context);
        View view1 = LayoutInflater.from(context).inflate(R.layout.likes_wish_toast, null);
        ImageView logoPhoto = (ImageView) view1.findViewById(R.id.logoPhoto_likes_wish_toast);
        Picasso.with(context).load(stringT).into(logoPhoto);
        toast.setGravity(Gravity.BOTTOM, 0, 20);
        toast.setView(view1);
        toast.show();

        //开线程，Toast  time时间后，退出Toast
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                toast.cancel();
            }
        }, time);
    }
}
